Task runner
Set of methods to synchronize asynchronous operations.
Installation
npm install @cjssdk/runner
Usage
Add to the scope:
var Runner = require('@cjssdk/runner'),
runner = new Runner();
Create a simple sync task:
runner.task('lint', function () {
});
Create a simple async task:
runner.task('build', function ( done ) {
someAsyncCall(function () {
done();
});
});
Create a task with serial subtasks:
runner.task('serve', runner.serial('lint', 'build'));
Create a task with parallel subtasks:
runner.task('build', runner.parallel('jade:build', 'sass:build'));
It's possible to use either anonymous or named functions as well:
runner.task('build', runner.parallel('jade:build', 'sass:build', function lessBuild ( done ) {
done();
}));
Batch tasks creation:
Object.assign(runner.tasks,
{
taskName1: taskFunction1,
taskName2: taskFunction2
},
{
taskName3: taskFunction3,
taskName4: taskFunction4
}
);
Execute a task by name:
runner.run('lint');
Execute a task and handle the result:
runner.run('lint', function ( error ) {
if ( error ) {
console.log('the task has failed!');
}
});
Execute a task as a named or anonymous function:
runner.run(function ( done ) {
done();
});
Execute task series:
runner.run(runner.parallel('lint', 'build'));
Execute task chain:
runner.start();
runner.start(function () {
console.log('finished');
});
runner.start(function ( error ) {
if ( error ) {
console.log('failed!');
}
});
Hook on task start/stop events:
runner.addListener('start', function ( event ) {
console.log(event);
});
runner.addListener('finish', function ( event ) {
console.log(event);
});
Contribution
If you have any problems or suggestions please open an issue
according to the contribution rules.
License
@cjssdk/runner
is released under the MIT License.